<template>
  <el-dialog
    :visible.sync="reptileLogDialogVisible"
    width="45%"
    top="70px"
    @open="open"
    :before-close="closeDialog"
  >
    <div slot="title">
      {{ reptileLogName.en_name }}
    </div>
    <span class="main">
      <!-- <div v-if="tableList.length != 0">
        <div
          :key="index"
          v-for="(item, index) in logArr"
          class="reptile-log"
          :style="item.error == 1 ? 'color:#F56C6C' : ''"
        >
          {{ item.str }}
        </div>
      </div>
      <div v-else>No data ...</div> -->
      <el-tabs v-model="logClass" @tab-click="handleClick">
        <el-tab-pane
          :label="$t('reptileDialog.table.craw_log')"
          name="1"
        ></el-tab-pane>
        <el-tab-pane
          :label="$t('reptileDialog.table.craw_adnor_log')"
          name="2"
        ></el-tab-pane>
      </el-tabs>
      <el-table
        v-loading="loading"
        element-loading-text="Loading...."
        border
        :data="logClass == 1 ? normalList : abnormalList"
        style="width: 100%; margin-top: -14px"
      >
        <!-- <el-table-column
          type="index"
          width="65"
          :label="$t('reptileDialog.table.index')"
        >
        </el-table-column> -->

        <el-table-column
          :prop="reptile_type == 1 ? 'crawl_day' : 'datetime'"
          :label="$t('reptileDialog.table.craw_time')"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          v-if="reptile_type != 1 && logClass == 1"
          key="6"
          prop="intervalseconds"
          :label="$t('reptileDialog.table.file_time')"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          v-if="reptile_type != 1 && logClass == 1"
          key="7"
          prop="logmsg"
          :label="$t('reptileDialog.table.craw_file')"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          v-if="reptile_type != 1 && logClass == 1"
          key="8"
          prop="untransferfiles"
          :label="$t('reptileDialog.table.radio_file')"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          v-if="reptile_type == 1"
          key="2"
          prop="category"
          :label="$t('reptileDialog.table.craw_cate')"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column
          v-if="reptile_type == 1"
          key="3"
          prop="start_time"
          show-overflow-tooltip
          :label="$t('reptileDialog.table.start_time')"
        >
        </el-table-column>
        <el-table-column
          v-if="reptile_type == 1"
          key="4"
          prop="end_time"
          show-overflow-tooltip
          :label="$t('reptileDialog.table.end_time')"
        >
        </el-table-column>
        <el-table-column
          v-if="logClass == 1 && reptile_type == 1"
          key="1"
          prop="item_count"
          :label="$t('reptileDialog.table.num')"
        >
        </el-table-column>
        <el-table-column
          :label="$t('reptileDialog.table.abnor_info')"
          v-if="logClass == 2"
          key="5"
        >
          <template slot-scope="{ row }">
            <el-popover
              effect="dark"
              placement="top-start"
              width="750"
              trigger="click"
            >
              <div style="white-space: pre-wrap">
                {{ reptile_type == 1 ? row.error : row.exceptionlog }}
              </div>
              <div class="reptileError" slot="reference">
                {{ reptile_type == 1 ? row.error : row.exceptionlog }}
              </div>
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column
          prop="isresolved"
          :label="$t('reptileDialog.table.is_ok')"
          v-if="reptile_type != 1 && logClass == 2"
          key="10"
          show-overflow-tooltip
        >
          <span slot-scope="{ row }">{{
            row.isresolved == 0
              ? $t("reptileDialog.table.no_ok")
              : $t("reptileDialog.table.ok")
          }}</span>
        </el-table-column>
      </el-table>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">{{
        $t("reptileDialog.btn.close")
      }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: ["reptileLogDialogVisible", "reptileLogName", "projectOptions"],
  data() {
    return {
      loading: false,
      tableData: null,
      normalList: [],
      abnormalList: [],
      logArr: [],
      logClass: "1",
      reptile_type: 0,
    };
  },
  methods: {
    open() {
      this.getTableData();
    },
    // 获取所有的日志信息
    async getTableData() {
      this.loading = true;
      this.reptile_type = this.projectOptions.find((val) => {
        return val.id == this.reptileLogName.project_id;
      }).type;
      console.log(this.reptile_type);
      let params = {
        en_name: this.reptileLogName.en_name,
        reptile_type: this.reptile_type,
        project_id: this.reptileLogName.project_id,
      };
      const { data: res } = await this.$http.get("/crawl/log", {
        params: params,
      });
      console.log(res);
      this.tableData = res;
      this.normalList = res.normal_data;
      this.abnormalList = res.abnormal_data;
      // {code:0,normal_data:[],abnormal_data:[]}
      this.loading = false;
    },
    //  切换正常和异常的数据
    handleClick() {},
    closeDialog() {
      this.$emit("closeDialog");
    },
  },
};
</script>

<style lang="less" scoped>
.reptile-log {
  font-size: 16px;
  // height: 30px;
  line-height: 30px;
  color: #5e5e5e;
  .red {
    color: red !important;
  }
}
.reptileError {
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
}
</style>